<?php
namespace Modules\User\Controllers;

class ParentController extends \Phalcon\Mvc\Controller {
	public function initialize() {
		$this -> response -> setStatusCode(200, 'OK') -> sendHeaders() -> setContentType('application/json', 'UTF-8');
	}

	public function indexAction($id) {
		$res = $this -> user::getServiceInstance() -> findFirst([
			'columns' => 'pid',
			'conditions' => 'user_id = ' . $id
		]);

		$service = $this -> user::getServiceInstance() -> findFirst([
			'columns' => 'user_id, account',
			'conditions' => 'user_id = ' . $res['user'] -> pid,
			'order' => 'user_id DESC'
		]);
		if($service['code'] != 0) {
			return $this -> response -> setJsonContent(['code'=>$service['code'],'msg'=>'无推荐人']);
		}

		return $this -> response -> setJsonContent(['code'=>0,'msg'=>'Success', 'models' => [$service['user']]]);
	}
}